<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .inner {
            margin-top: 20px;
            height: 150px;
            background-color: darkcyan;
        }

        .foo {
            margin-top: 20px;
            height: 50px;
        }

        .outer {
            margin-top: 20px;
            padding: 30px;
            background-color: lightcoral;
        }
    </style>
    <script src="./lib/vue2.4.4.js"></script>
</head>

<body>
    <div id="app">

        <div class="outer" @click="divOuterHandler">
            <div class="inner" @click.self="divHandler">
                <input type="button" value="stop 与 self 的比较" @click="btnHandler">
            </div>
        </div>

        <div class="outer" @click="divOuterHandler">
            <div class="inner" @click="divHandler">
                <input type="button" value="stop 与 self 的比较" @click.stop="btnHandler">
            </div>
        </div>

        <div class="foo">
            <a href="http://www.baidu.com" @click.prevent.once="linkClick">once只执行一次</a>
        </div>

        <!-- `.self` 阻止事件被动触发 -->
        <div class="inner" @click.self="divHandler">
            <input type="button" value="戳他" @click="btnHandler">
        </div>

        <!-- `.capture` 以捕获方式触发事件，与"冒泡"相反 -->
        <div class="inner" @click.capture="divHandler">
            <input type="button" value="戳他" @click="btnHandler">
        </div>

        <div class="foo">
            <!-- 使用 `.prevent` 阻止默认行为 -->
            <a href="http://www.baidu.com" @click.prevent="linkClick">阻止默认行为</a>
        </div>

        <div class="inner" @click="divHandler">
            <!-- 使用`.stop`阻止冒泡 -->
            <input type="button" value="戳他" @click.stop="btnHandler">
        </div>


    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            data: {
            },
            methods: {
                linkClick() {
                    console.log('## 触发了 a 链接的点击事件');
                },
                divHandler() {
                    console.log('^^ 触发了inner div的点击事件');
                },
                btnHandler() {
                    console.log('vv 触发了button的点击事件');
                },
                divOuterHandler() {
                    console.log('`` 触发了outer div的点击事件');
                }
            }
        });
    </script>
</body>

</html>